#!/bin/sh
#update router's ssr data
#2019/12/28
#kevin

ssrjsondir=/etc/config/ssrpro
ssrdir="/etc/init.d/ssrpro restart"
dir=/root/ssr/ssr.txt
ip=
port=
passwd=

#get ssr keys and values
for line in `tail -n 10 $dir | head -n 5`
	do
	key=`echo $line | cut -d ':' -f1`
        value=`echo $line | cut -d ':' -f2`
	#echo $key $value
	case $key in
		IPAddress)
				ip=$value
				#echo $ip
				;;
		Port)
				port=$value
				#echo $port
				;;
		Password)
				passwd=$value
				#echo $passwd
				;;
	esac	
	done

#update ssr data
#cat $ssrjsondir | sed 's/server .*/server '\'$ip\''/g; s/server_port.*/server_port '\'$port\''/g; s/password.*/password '\'$passwd\''/g'
#cat $ssrjsondir
sed -i 's/server .*/server '\'$ip\''/g; s/server_port.*/server_port '\'$port\''/g; s/password.*/password '\'$passwd\''/g' $ssrjsondir
#restart ssrpro
$ssrdir > /dev/null
